Don't intermingle targets between packages
authorAlex Crichton <alex@alexcrichton.com>
Wed, 11 Mar 2015 20:32:59 +0000 (13:32 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 11 Mar 2015 20:32:59 +0000 (13:32 -0700)
When loading targets to compile, be sure to use the targets from the package
that's being passed down to the compilation step, not the one that was passed in
which is overridden.

Closes #1404

src/cargo/ops/cargo_compile.rs
tests/test_cargo_package.rs

index 2c8fd0b1aa31f55cff8d2e81386b851dfcf7d45b..e848ce9f1305ed305277458da314146b6512571b 100644 (file)
@@ -131,14 +131,11 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)
         (packages, resolved_with_overrides, registry.move_sources())
     };
 
-    let to_build = match spec {
-        Some(spec) => {
-            let pkgid = try!(resolve_with_overrides.query(spec));
-            packages.iter().find(|p| p.package_id() == pkgid).unwrap()
-        }
-        None => package,
+    let pkgid = match spec {
+        Some(spec) => try!(resolve_with_overrides.query(spec)),
+        None => package.package_id(),
     };
-
+    let to_build = packages.iter().find(|p| p.package_id() == pkgid).unwrap();
     let targets = to_build.targets().iter().filter(|target| {
         target.profile().is_custom_build() || match env {
             // doc-all == document everything, so look for doc targets
index c2c2ab447278d66dba0a97b51e01c57b02c3e39c..a3fcbbcb07b3c2a331d8fc658bacf54c05d25513 100644 (file)
@@ -244,3 +244,21 @@ test!(include {
 {archiving} [..]
 ", packaging = PACKAGING, archiving = ARCHIVING).as_slice()));
 });
+
+test!(package_lib_with_bin {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", r#"
+            extern crate foo;
+            fn main() {}
+        "#)
+        .file("src/lib.rs", "");
+
+    assert_that(p.cargo_process("package").arg("-v"),
+                execs().with_status(0));
+});